package com.csair.seam.domain.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.csair.seam.controller.pc.IdleShowContrlloer;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel
@TableName("idle_show")
public class IdleShow {

    @ApiModelProperty(value="发布id")
    @TableField("show_id")
    private Integer showId;

    @ApiModelProperty(value="图片地址")
    @TableField("pic_data")
    private String picData;

    @NotBlank(message = "设备名称不能是空")
    @Length(min=0,max = 25,message = "设备名称字数 1<设备名称<255")
    @ApiModelProperty(value="设备名称")
    @TableField("equip_name")
    private String equipName;

    @NotBlank(message = "公司名称不能是空")
    @Length(max = 255,message = "公司名称字数 1<公司名称<255")
    @ApiModelProperty(value="原公司名称")
    @TableField("corpName")
    private String corpName;

    @NotBlank(message = "公司编码不能是空")
    @Length(max = 255,message = "公司编码字数 1<公司编码字数<255")
    @ApiModelProperty(value="原公司名称")
    @TableField(exist = false)
    private String corpCode;

    @NotBlank(message = "部门名称不能是空")
    @Length(max = 255,message = "部门名称字数 1<部门名称<255")
    @ApiModelProperty(value="原部门名称")
    @TableField("deptName")
    private String deptName;

    @NotBlank(message = "部门编码不能是空")
    @Length(max = 255,message = "部门编码字数 1<部门名称<255")
    @ApiModelProperty(value="原部门名称")
    @TableField(exist = false)
    private String deptCode;


    @NotBlank(message = "设备品牌不能是空")
    @Length(max = 25,message = "设备品牌字数 1<设备品牌<25")
    @ApiModelProperty(value="设备品牌")
    @TableField("equip_brand")
    private String equipBrand;

    @NotBlank(message = "型号不能是空")
    @Length(max = 25,message = "型号字数 1<型号<25")
    @ApiModelProperty(value="型号")
    @TableField("equip_model")
    private String equipModel;

    @ApiModelProperty(value="开始时间")
    @TableField("begin_time")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date begintTime;

    @TableField("equip_codes")
    private String equipCodes;

    @Max(value = 999999999,message = "设备数量 0<设备数量<999999999")
    @Min(value = 0,message = "设备数量 0<设备数量<999999999")
    @TableField("equip_num")
    private  Integer equipNum;

    @Max(value = 999999999,message = "设备金额 0<设备金额<999999999")
    @Min(value = 0,message = "设备金额 0<设备金额<999999999")
    @ApiModelProperty(value="设备金额")
    @TableField("equip_nsum")
    private BigDecimal equipNsum;


    @NotBlank(message = "技术参数不能是空")
    @Length(min=10,max = 255,message = "技术参数字数 10<设备编码<255")
    @ApiModelProperty(value="技术参数")
    @TableField("technicals")
    private String technicals;

    @Length(max = 255,message = "详情字数 1<设备编码<255")
    @ApiModelProperty(value="详情")
    @TableField("moredetails")
    private String moredetails;

    @Length(max = 25,message = "联系人字数 1<设备编码<25")
    @ApiModelProperty(value="联系人")
    @TableField("operator")
    private String operator;

    @Length(max = 25,message = "手机号码字数 1<设备编码<25")
    @ApiModelProperty(value="手机号码")
    @TableField("phone_num")
    private String phoneNum;

    @Length(max = 255,message = "状态字数 1<设备编码<255")
    @ApiModelProperty(value="状态")
    @TableField("billstatus")
    private String billstatus;

    @ApiModelProperty(value="创建者")
    @TableField("creator")
    private String creator;

    @ApiModelProperty(value="创建时间")
    @TableField("creat_time")
    private Date creatTime;

    @TableField("show_code")
    public String showCode;


    @Length(max = 60,message = "email字数 1<设备编码<60")
    @Email(message = "email格式不正确")
    @ApiModelProperty(value="email")
    @TableField("email")
    private String email;

    @Max(value = 999999999,message = "净值单价 0<净值单价<999999999")
    @Min(value = 0,message = "净值单价 0<净值单价<999999999")
    @ApiModelProperty(value="净值单价")
    @TableField("nsum")
    private BigDecimal nsum;

    @ApiModelProperty(value="设备编码")
    @TableField(exist = false)
    private List<IdleShow> equipCodeList;

    @ApiModelProperty(value="数量")
    @TableField(exist = false)
    private String equipNums;

    @NotBlank(message = "设备位置不能是空值")
    @Length(max = 60,message = "email字数 1<设备编码<60")
    @ApiModelProperty(value="设备位置")
    @TableField(exist = false)
    private String equipLocation;

    @ApiModelProperty(value="flag不能是空值｜true代表有设备编码，false代表无设备编码,默认是true")
    @NotNull(message = "flag不能是空值｜true代表有设备编码，其他值代表无设备编码，默认是true")
    @TableField(exist = false)
    private String flag = "true";

    @NotBlank(message = "设备大类不能是空值")
    @Length(max = 25,message = "email字数 1<设备编码<25")
    @ApiModelProperty(value="设备大类")
    @TableField("category")
    private String category;

    private  List<String> categorys = new ArrayList<>();

    public boolean  isCategorys(String category){
		categorys.add("机务工具");
		categorys.add("IT设备");
		categorys.add("通用车辆");
		categorys.add("特种车辆");
		categorys.add("其他");
		return categorys.contains(category);
}

    public IdleShow(IdleShow idleShow) {
        this.showId = idleShow.showId;
        this.picData = idleShow.picData;
        this.equipName = idleShow.equipName;
        this.corpName = idleShow.corpName;
        this.corpCode = idleShow.corpCode;
        this.deptName = idleShow.deptName;
        this.deptCode = idleShow.deptCode;
        this.equipBrand = idleShow.equipBrand;
        this.equipModel = idleShow.equipModel;
        this.begintTime = idleShow.begintTime;
        this.equipCodes = idleShow.equipCodes;
        this.equipNum = idleShow.equipNum;
        this.equipNsum = idleShow.equipNsum;
        this.technicals = idleShow.technicals;
        this.moredetails = idleShow.moredetails;
        this.operator = idleShow.operator;
        this.phoneNum = idleShow.phoneNum;
        this.billstatus = idleShow.billstatus;
        this.creator = idleShow.creator;
        this.creatTime = idleShow.creatTime;
        this.showCode = idleShow.showCode;
        this.email = idleShow.email;
        this.nsum = idleShow.nsum;
        this.equipCodeList = idleShow.equipCodeList;
    }

    public IdleShow() {
    }

    public boolean isFlag(){
        return StringUtils.equals("true", flag) ? true:false;
    }


    /**
     *检验
     *  eamail值是否为空
     *  联系人不能是空值
     *  联系电话不能是空值
     * @param idleShow
     * @return
     */
    public List<String> checkIdleShow(){

        List<String> errors = new ArrayList<>();
        checkIdleShow
                (StringUtils.isEmpty(this.getEmail()),"【email不是空值】",errors)
                .checkIdleShow(StringUtils.isEmpty(this.getOperator()),"【联系人不能是空值】",errors)
                .checkIdleShow(StringUtils.isEmpty(this.getPhoneNum()),"【联系电话不能是空值】",errors);
        return errors;
    }

    private IdleShow checkIdleShow(boolean condition, String errorMeeage, List<String> error){
        if(condition){
            error.add(errorMeeage);
        }
        return this;
    }
}
